﻿Imports TBCC.Utility

''' <summary>
''' 压缩机端口服务类
''' </summary>
''' <remarks></remarks>
Public Class CcapCompressorPortItemServices

    ''' <summary>
    ''' 默认构造函数
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()

    End Sub


    ''' <summary>
    ''' 查询压缩机的端口
    ''' </summary>
    ''' <param name="cpId">压缩机编号</param>
    ''' <returns>返回压缩机端口信息</returns>
    ''' <remarks>数据集包换字段：Id ,cpId ,cpLowPressAlarmPort ,cpHighPressAlarmPort ,cpOileAlarmPort ,cpChargeTAlarmPort</remarks>
    Public Function GetPorts(ByVal cpId As Integer) As DataSet
        Dim ds As DataSet = Nothing
        Dim strSql As String = String.Empty

        strSql = " SELECT Id ,cpId ,cpLowPressAlarmPort ,cpHighPressAlarmPort ,cpOileAlarmPort ,cpChargeTAlarmPort ,cpOverLoadAlarmPort,cpActiveStatePort " + _
                " FROM `tbccCompressorPortSet` WHERE `cpId` =  " + cpId.ToString()

        Try
            ds = SqlHelper.ExecuteDataset(strSql, Nothing)
        Catch ex As Exception
            ds = Nothing
        End Try

        Return ds
    End Function

    ''' <summary>
    ''' 查询项目包含的压缩机及报警端口
    ''' </summary>
    ''' <param name="projectId">项目编号</param>
    ''' <returns> Id,csId,csNetId,name,cpLowPressAlarmPort,cpHighPressAlarmPort,cpOileAlarmPort,cpChargeTAlarmPort,cpOverLoadAlarmPort</returns>
    ''' <remarks></remarks>
    Function GetGroupNameAndPorts(ByVal ProjectId As String) As DataSet
        Dim ds As DataSet = Nothing
        Dim strSql As String = String.Empty

        strSql = " SELECT P.Id,C.csId,T.csNetId,CONCAT(G.Csname , C.Name ) AS 'name',P.cpLowPressAlarmPort,P.cpHighPressAlarmPort,P.cpOileAlarmPort,P.cpChargeTAlarmPort,P.cpOverLoadAlarmPort,P.cpActiveStatePort " & _
                " FROM tbcccompressorportset AS P Inner Join tbcccompressor AS C ON P.cpId = C.Id " & _
                " Inner Join tbcccompressorset AS G ON G.Id = C.csId  Inner Join tbccccapdevtype AS T ON G.DevId = T.Id " & _
                " WHERE T.csNetId>=50  And T.ProjectID='" + ProjectId + "'"

        Try
            ds = TBCC.Utility.SqlHelper.ExecuteDataset(strSql, Nothing)
        Catch ex As Exception
            ds = Nothing
        End Try

        Return ds
    End Function
    ''' <summary>
    ''' 更新压缩机端口
    ''' </summary>
    ''' <param name="Com"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function InsertCompressorPort(ByVal Com As CcapCompressorPortItem) As Boolean
        Dim strSql As String
        Dim tic As New TBCC.Utility.TranstrationItem


        strSql = String.Format("delete from tbcccompressorportset where cpId='{0}'", Com.CpId)
        tic.Add(strSql, Nothing)
        strSql = "Insert into tbcccompressorportset(cpId,cpLowPressAlarmPort,cpHighPressAlarmPort,cpOileAlarmPort,cpChargeTAlarmPort,cpOverLoadAlarmPort,cpActiveStatePort) Values(?p0,?p1,?p2,?p3,?p4,?p5,?p6)"

        Dim p1(6) As System.Data.Common.DbParameter

        p1(0) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(0).ParameterName = "p0" : p1(0).Value = Com.CpId

        p1(1) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(1).ParameterName = "p1" : p1(1).Value = Com.cpLowPressAlarmPort

        p1(2) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(2).ParameterName = "p2" : p1(2).Value = Com.cpHighPressAlarmPort
        p1(3) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(3).ParameterName = "p3" : p1(3).Value = Com.cpOileAlarmPort

        p1(4) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(4).ParameterName = "p4" : p1(4).Value = Com.cpChargeTAlarmPort
        p1(5) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(5).ParameterName = "p5" : p1(5).Value = Com.cpOverLoadAlarmPort

        p1(6) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(6).ParameterName = "p6" : p1(6).Value = Com.cpActiveStatePort

        tic.Add(strSql, p1)


        Return TBCC.Utility.SqlHelper.ExecuteTranstration(tic)

    End Function
End Class
